package com.zhongge.operations;

import com.zhongge.book.Book;
import com.zhongge.book.BookList;

import java.util.Scanner;

@SuppressWarnings("all")
/**
 * @ClassName BorrowBook
 * @Description TODO 借阅图书
 * @Author zhongge
 * @Date 2025/7/14 19:33
 * @Version 1.0
 */
public class BorrowBook implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的书名:");
        String name = scanner.nextLine();
        //判断是否有这本书
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if (name.equals(book.getName())) {
                System.out.println("借阅成功");
                book.setBorrow(true);
                return;
            } else {
                System.out.println("借阅失败，此书不存在");
                return;
            }
        }
    }
}
